using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Modularity;
using Volo.Abp.Application;
using Volo.Abp.Caching;
using Volo.Abp.Identity;
using Volo.Abp.EventBus;
using Volo.Abp.Authorization;
using AuthService.Domain;
using MatrixFramework.Keycloak;
using MatrixFramework.Keycloak.Abstractions.Services;
using MatrixFramework.Keycloak.Abstractions.Options;
using AuthService.Options;

namespace AuthService;

[DependsOn(
    typeof(AbpDddApplicationModule),
    typeof(AbpAutoMapperModule),
    typeof(AbpCachingModule),
    typeof(AbpIdentityApplicationModule),
    typeof(AbpEventBusModule),
    typeof(AbpAuthorizationModule),
    typeof(AuthServiceDomainModule),
    typeof(MatrixFrameworkKeycloakModule)
)]
public class AuthServiceApplicationModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpAutoMapperOptions>(options =>
        {
            options.AddMaps<AuthServiceApplicationModule>();
        });

        // 配置Keycloak选项
        var configuration = context.Services.GetConfiguration();
        Configure<KeycloakOptions>(configuration.GetSection(KeycloakOptions.SectionName));

        // 配置AuthService选项
        Configure<AuthServiceOptions>(configuration.GetSection("AuthService"));

        // 注册Keycloak服务
        context.Services.AddScoped<IKeycloakAdminService, KeycloakAdminService>();
    }
}